package com.ksyun.campus.dataserver.config.zookperconfig;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import java.time.temporal.ChronoUnit;

/**
 * @author sxt
 * @version 1.0
 * @description TODO
 * @date 2023/8/9 20:51
 */
@SuppressWarnings("LombokGetterMayBeUsed")
@ConfigurationProperties(prefix = "zookeeper")
public class ZookeeperConfigProperties implements EnvironmentAware {

    private Environment environment;

    private String address;

    private ChronoUnit unit = ChronoUnit.MILLIS;

    private int timeout;

    public String getAppName() {
        String name = environment.getProperty("spring.application.name");
        return StringUtils.hasText(name) ? name : "data-server";
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    public void setUnit(ChronoUnit unit) {
        this.unit = unit;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public Environment getEnvironment() {
        return environment;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public ChronoUnit getUnit() {
        return unit;
    }

    public int getTimeout() {
        return timeout;
    }

}
